/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pope.jloading;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Zouxuewei pope945@gmail.com
 */
public class Elog {

    public Elog() {
    }
  
    public static void log(String message) {
        try {
            File logPath = new File("logs");
            if (!logPath.exists()) {
                logPath.mkdirs();
            }
            Date theDate = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String fileName = "log" + sdf.format(theDate) + ".txt";
            sdf.applyPattern("HH:mm:ss");
            String nowTime = sdf.format(theDate);
            File logFile = new File(logPath, fileName);
            FileWriter fw = null;
        
            fw = new FileWriter(logFile, true);
            fw.write("Log:[" + nowTime + "]");
            fw.write(message + "\r\n");
            fw.flush();
            fw.close();
        } catch (IOException ioe) {
            //System.out.println("Elog:log:I/O Error");
        }
     }
}
